package algorythms;

import individuals.Individual;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Torneos {
	private int t;
	private static Random ranGen = new Random(127);
	
	public Torneos(int t) {
		this.t = t;
	}
	
	public List<Individual> applyAlgorythm(List<Individual> population, int n) {
		List<Individual> list = new ArrayList<Individual>();
		int i,j;
		
		for(i=0; i<n; i++) {
			List<Individual> listAux = new ArrayList<Individual>();
			for(j=0; j<this.t; j++) {
				listAux.add(population.get((int)Math.floor(ranGen.nextDouble()*population.size())));
			}
			Individual best = listAux.get(0);
			for(Individual ind: listAux)
				if(ind.getAptitud()>best.getAptitud())
					best=ind;
			list.add(best);
		}
		
		return list;
	}

}
